

public class CollisionRect {
	
	int 	x, y; // Upper Left Corner
	int     width, height; // Lower Right Corner
	boolean valid;

	void SetPosition(int newX, int newY){
		x 		= newX;
		y 		= newY;
	}

	void SetPosition(float newX, float newY){
		x 		= (int) newX;
		y 		= (int) newY;
	}
	
	void SetDimensions(boolean newValid, int newW, int newH){
		valid 	= newValid;
		width   = newW;
		height  = newH;
	}

	// IsAbove
	// Other rectangle is above this one
	boolean IsValid(){
		return valid;
	}
	
	// IsAbove
	// Other rectangle is above this one
	boolean IsAbove(CollisionRect otherRect){
		boolean above = false;
		if( (otherRect.y + otherRect.height) < y)
			above = true;
		return above;
	}

	// IsBelow
	// Other rectangle is below this one
	boolean IsBelow(CollisionRect otherRect){
		boolean below = false;
		if( otherRect.y  >  (y + height) ) 
			below = true;
		return below;
	}
	
	// IsRightOf
	// Other rectangle is to the right of
	boolean IsRightOf(CollisionRect otherRect){
		boolean rightOf = false;
		if( otherRect.x  >  (x + width) ) 
			rightOf = true;
		return rightOf;
	}

	// IsLeftOf
	// Other rectangle is to the left of
	boolean IsLeftOf(CollisionRect otherRect){
		boolean leftOf = false;
		if( (otherRect.x + otherRect.width) < x ) 
			leftOf = true;
		return leftOf;
	}

	CollisionType CheckCollide( CollisionRect otherRect){
		CollisionType col = CollisionType.COLLISION;    // Default to collide

		if( ! (valid & otherRect.valid) ) // Check if both rectangles are valid
			col = CollisionType.NONE;
		else if( IsAbove(otherRect) )	  // Check if other rectangle is higher than this one
			col = CollisionType.ABOVE;
		else if( IsBelow(otherRect) )        // Check if other rectangle is lower than this one
			col = CollisionType.BELOW;
		else if( IsRightOf(otherRect) )        // Check if other rectangle is right of this one
			col = CollisionType.RIGHT_OF;
		else if( IsLeftOf(otherRect) )        // Check if other rectangle is left of this one
			col = CollisionType.LEFT_OF;
			
		return col;
	}
	
	
	void CopyDimensions(CollisionRect rect){
		this.width  = rect.width;
		this.height = rect.height;
		this.valid  = rect.valid;
	}
}
